import { apiClient } from './client';
import { API_ENDPOINTS } from './config';
import type {
  RegisterRequest,
  RegisterResponse,
  SendEmailRequest,
  SendEmailResponse,
  LoginRequest,
  LoginResponse,
  SettingCodeRequest
} from '../types/auth';

export const authApi = {
  // 发送验证码
  sendEmail: async (data: SendEmailRequest & { scene?: string }): Promise<SendEmailResponse> => {
    if (data.scene) {
      // @ts-ignore
      delete data.scene
    }
    return apiClient.post(API_ENDPOINTS.SEND_EMAIL, data, {
      retry: true,
      retryCount: 3,
      headers: { skipAuth: true }
    });
  },

  // 发送场景验证码
  sendVerifyCode: async (data: { Scene: string }): Promise<void> => {
    return apiClient.post(API_ENDPOINTS.SEND_VERIFY_CODE, data);
  },

  // 注册
  register: async (data: RegisterRequest): Promise<RegisterResponse> => {
    return apiClient.post(API_ENDPOINTS.REGISTER, data, {
      retry: true,
      retryCount: 2,
      headers: { skipAuth: true }
    });
  },

  // 登录
  login: async (data: LoginRequest): Promise<LoginResponse> => {
    return apiClient.post(API_ENDPOINTS.LOGIN, data, {
      retry: true,
      retryCount: 2,
      headers: { skipAuth: true }
    });
  },

  // 是否设置过谷歌验证码
  isSettingCode: async (params: SettingCodeRequest): Promise<void> => {
    return apiClient.get("/api/v1/login/google-verify", { params });
  },
};